/*
 * Copyright 2010 Pierre Heinzerling, Uwe Janner, Patrick Wright
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.upp.publinksky.model;

import com.google.appengine.api.datastore.Key;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;

@PersistenceCapable
@XmlRootElement(name="comment")
public class LinkComment {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private Key theme;
    private int themeId;
    @Persistent
    private String uriString;
    @Persistent
    private String userEmail;
    @Persistent
    private String note;
    @Persistent
    private boolean isGood;
    @Persistent
    private Date lastUpdated;
    @Persistent
    private int themeLastUpdateCounter;

    public LinkComment() {
    }

    public Key getKey() {
        return key;
    }

    public void setKey(final Key key) {
        this.key = key;
    }

    public Key getTheme() {
        return theme;
    }

    public void setTheme(final Key theme) {
        this.theme = theme;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(final String userEmail) {
        this.userEmail = userEmail;
    }

    public String getNote() {
        return note;
    }

    public void setNote(final String note) {
        this.note = note;
    }

    public boolean isGood() {
        return isGood;
    }

    public void setGood(final boolean good) {
        isGood = good;
    }

    public Date getLastUpdated() {
        return lastUpdated;
    }

    public void setLastUpdated(final Date lastUpdated) {
        this.lastUpdated = lastUpdated;
    }

    public String getUriString() {
        return uriString;
    }

    public void setUriString(final String uriString) {
        this.uriString = uriString;
    }

    public int getThemeId() {
        return themeId;
    }

    public void setThemeId(final int themeId) {
        this.themeId = themeId;
    }

    public void setThemeLastUpdateCounter(final int lastUpdateCounter) {
        themeLastUpdateCounter = lastUpdateCounter;
    }

    public int getThemeLastUpdateCounter() {
        return themeLastUpdateCounter;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) return true;
        if (!(o instanceof LinkComment)) return false;

        final LinkComment that = (LinkComment) o;

        if (isGood != that.isGood) return false;
        if (key != null ? !key.equals(that.key) : that.key != null) return false;
        if (lastUpdated != null ? !lastUpdated.equals(that.lastUpdated) : that.lastUpdated != null) return false;
        if (note != null ? !note.equals(that.note) : that.note != null) return false;
        if (theme != null ? !theme.equals(that.theme) : that.theme != null) return false;
        if (uriString != null ? !uriString.equals(that.uriString) : that.uriString != null) return false;
        if (userEmail != null ? !userEmail.equals(that.userEmail) : that.userEmail != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = key != null ? key.hashCode() : 0;
        result = 31 * result + (theme != null ? theme.hashCode() : 0);
        result = 31 * result + (uriString != null ? uriString.hashCode() : 0);
        result = 31 * result + (userEmail != null ? userEmail.hashCode() : 0);
        result = 31 * result + (note != null ? note.hashCode() : 0);
        result = 31 * result + (isGood ? 1 : 0);
        result = 31 * result + (lastUpdated != null ? lastUpdated.hashCode() : 0);
        return result;
    }
}
